//
//  JokesViewController.m
//  XIWenLeJian
//
//  Created by lanou3g on 15/11/11.
//  Copyright © 2015年 蓝足. All rights reserved.
//

#import "JokesViewController.h"
#import "TextViewController.h"
#import "PictureViewController.h"

@interface JokesViewController ()

@property (nonatomic, strong) UISegmentedControl *segmentController;
/**文字视图控制器*/
@property (nonatomic, strong) TextViewController *textVC;
/**图片视图控制器*/
@property (nonatomic, strong) PictureViewController *pictureVC;

@end

@implementation JokesViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //segmentController添加点击事件
    [self.segmentController addTarget:self action:@selector(segmentClick) forControlEvents:(UIControlEventValueChanged)];

}

//懒加载
- (UISegmentedControl *)segmentController
{
    if (_segmentController == nil) {
        
        _segmentController = [[UISegmentedControl alloc] initWithItems:@[@"段子",@"醉了"]];
        _segmentController.frame = CGRectMake(0, 0, 150, 30);
        _segmentController.selectedSegmentIndex = 0;
        self.navigationItem.titleView = _segmentController;
        
    }
    return _segmentController;
}

//segmentController点击事件
- (void)segmentClick
{
    if (_segmentController.selectedSegmentIndex == 0) {
        
        [self.view addSubview:self.textVC.view];
    }else{
        
        [self.view addSubview:self.pictureVC.view];
    }
    
}

//懒加载
- (TextViewController *)textVC
{
    if (_textVC == nil) {
        
        _textVC = [[TextViewController alloc] init];
    }
    return _textVC;
}

//懒加载
- (PictureViewController *)pictureVC
{
    if (_pictureVC == nil) {
        
        _pictureVC = [[PictureViewController alloc] init];
    }
    return _pictureVC;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 0;
}

/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
